package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.AppMainOptimal;
import com.addplus.townmall.server.api.model.town.expand.AppMainOptimalExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * App首页商城优选 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-08-27
 */
public interface AppMainOptimalMapper extends BaseAddMapper<AppMainOptimal> {

    @Select("SELECT\n" +
            " amo.*,\n" +
            " o.sale_price,\n" +
            " o.line_price \n" +
            "FROM\n" +
            " app_main_optimal amo\n" +
            " LEFT JOIN optimal_shop AS o ON amo.shop_product_id = o.shop_product_id \n" +
            "WHERE\n" +
            " amo.is_deleted = 0 \n" +
            "ORDER BY\n" +
            " amo.sort DESC")
    List<AppMainOptimalExpand> getMainOptimalListByPage(IPage page);

    @Select("select IFNULL(max(sort)+1,1) as sort from app_main_optimal where is_deleted=0")
    Integer maxSort();
}
